package com.example.pokemon_integrado;

import com.Manager.SceneManager;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.util.Log;

public class DrawMenu {
private Bitmap bMap;
private Bitmap[] bButtons = new Bitmap[4];
private float[] W = new float[4], 
				H = new float[4],
				X = new float[4],
				Y = new float[4];
	
	public DrawMenu(Context context)
	{		
		this.bMap = BitmapFactory.decodeResource(context.getResources(), R.drawable.menu_background);
		this.bButtons[0] = BitmapFactory.decodeResource(context.getResources(), R.drawable.b_jogar);
		this.bButtons[1] = BitmapFactory.decodeResource(context.getResources(), R.drawable.b_credits);
		this.bButtons[2] = BitmapFactory.decodeResource(context.getResources(), R.drawable.b_sobre);
		this.bButtons[3] = BitmapFactory.decodeResource(context.getResources(), R.drawable.b_sair);
	}
	
	public void Draw(Canvas canvas, int W, int H, Paint p)
	{
		canvas.drawBitmap(getResizedBitmap(this.bMap,W,H),0,0,p);
		
		for(int i = 0; i<4; i++)
		{
			this.W[i] = (W*0.3f);
			this.H[i] = ((W*0.3f)/3.7f);
			this.X[i] = W*0.35f;
			this.Y[i] = (W*0.09f)*(i+2);
			canvas.drawBitmap(getResizedBitmap(this.bButtons[i], (int) this.W[i],(int) this.H[i]),this.X[i],this.Y[i],p);
		}
	}
	
	public void getTouch(float x, float y)
	{
		if(SceneManager.getInstance().currentScene == 1){
			for(int i = 0; i<4; i++){
				if(x > this.X[i] && x < this.X[i] + this.W[i] && y > this.Y[i] && y <this.Y[i] + this.H[i])
				{
					switch(i)
					{
						case 0:
							SceneManager.getInstance().currentScene = 2;
						break;
						
						case 1:
							SceneManager.getInstance().currentScene = 4;
							break;
							
						case 2:
							SceneManager.getInstance().currentScene = 5;
							break;
						
						case 3:
							SceneManager.getInstance().currentScene = 6;
							break;
					}
				}
			}
		}
	}
	
	public Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) 
	{

		int width = bm.getWidth();
		int height = bm.getHeight();

		float scaleWidth = ((float) newWidth) / width;
		float scaleHeight = ((float) newHeight) / height;

		Matrix matrix = new Matrix();
		matrix.postScale(scaleWidth, scaleHeight);
		
		Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);

		return resizedBitmap;
	}
}
